#include "background.h"

BackGround::BackGround(QGraphicsScene* m_scene)
{
    root = QFileInfo(__FILE__).absolutePath();//获取位置
    scene = m_scene;

    //引用Pixmap部分
    bg = new QPixmap(root+"/res/paper_background.jpg");
    fold =new QPixmap(root+"/res/fold_shadow.png");
    slider = new QPixmap(root+"/res/time_slider.png");
    slider_bg = new QPixmap(root+"/res/time_slider_back.png");
    lineH = new QPixmap(root+"/res/line.png");
    lineV = new QPixmap(root+"/res/line.png");
    *bg = bg->scaled(1600,930);
    *fold = fold->scaled(395,930);
    *lineH = lineH->scaled(1600,4);

    //设置sliderx的值
    sliderx = 294.0f;
    scene->addItem(this);

}
QRectF BackGround::boundingRect() const{
    return QRectF(0,0,bg->width(),bg->height());
}
void BackGround::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){
    painter->drawPixmap(0,0,*bg);
    painter->drawPixmap(600,0,*fold);

    //绘制slider
    painter->drawPixmap(300,50,*slider_bg);
    painter->drawPixmap(sliderx,38,*slider);

    for(int i=0;i<24;i++){
        painter->drawPixmap(0,i*40,*lineH);
    }
    for(int i=0;i<41;i++){
        painter->resetTransform();
        painter->translate(i*40,0);//调整位置
        painter->rotate(90);//转向
        painter->drawPixmap(0,0,*lineV);
    }
}

void BackGround::updateslider()
{
    if(sliderx<1314)
        sliderx +=0.5f;
    this->update();
}
